<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>运维人员配置</title>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script>
        function addOperator() {
            layer.open({
                type:2,//弹出iframe层
                title:'添加运维人员',
                area: ['380px', '330px'],
                content:'xuYiOperatorAdd.html'
            });
        }

        layui.use(['table', 'form', 'jquery','element','upload'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var upload = layui.upload;
            var tabledata = {
                elem: "#table",//表格id
                id: "modelReload", //id
                url: '/xuYiOperator/find',
                method: 'post',
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                page: true,
                count: "count",
                limit: 10,
                limits: [10, 20, 30, 40, 50],
                layout: ['prev', 'page', 'next'],
                prev: "上一页",
                next: "下一页",
                cols: [[ //表头
                    {field: 'operatorName', title: '运维人员名称',align:'center'}
                    , {field: 'operatorMsisdn', title: '运维人员手机号',align:'center'}
                    , {field: 'talkingCoding', title: '和对讲编码',align:'center'}
                    , {field: 'createTime', title: '创建时间',align:'center'},
                    {field: 'operation', title: '操作',align:'center', toolbar: '#barDemo'}
                ]]
            };

            upload.render({
                elem: '#import'
                , url: '/xuYiOperator/upload'
                , auto: false //关闭自动上传
                , accept: 'file' //普通文件
                , exts: 'csv' //只允许上传csv文件
                //,multiple: true
                , bindAction: '#upload'
                , number: '1'
                , multiple: 'false'
                , before: function (obj) {
                    layer.load(); //上传loading
                }
                , done: function (obj) {
                    layer.closeAll('loading'); //关闭loading

                    if (obj.data == 0) {
                        layer.open({
                            title: '导入失败',
                            content: '文件有误，请核对手机号及和对讲编码',
                            end:function () {
                                location.reload()
                            }
                        });
                    }else if (obj.data > 0){
                        layer.open({
                            title: '导入成功',
                            content: '成功导入' + obj.data + '位运维人员信息',
                            end:function () {
                                location.reload()
                            }
                        });
                    }else if (obj.code == -1){
                        layer.open({
                            title: '导入失败',
                            content: '系统异常',
                            end:function () {
                                location.reload()
                            }
                        });
                    }
                }
                , error: function (index, upload) {
                    layer.closeAll('loading'); //关闭loading
                    layer.msg("上传过程中出现异常，请重试");
                }
            });

            table.render(tabledata);
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('您确定要删除吗', {icon: 3, title: '提示'}, function (index) {
                        var url = "/xuYiOperator/remove";
                        var param = {
                            operatorId: data.operatorId
                        };
                        $.ajax({
                            type: 'post',
                            data: param,
                            url: url,
                            beforeSend: function () {
                            },
                            success: function (data) {
                                layui.use('layer', function () {
                                    if (data == 1) {
                                        layer.confirm('删除成功', {
                                            btn: ['确认'] //按钮
                                        }, function(){
                                            location.href = "xuYiOperatorManage.html";
                                        });
                                    }
                                    else {
                                        layer.confirm('删除失败，请重试', {
                                            btn: ['确认'] //按钮
                                        }, function(){
                                            location.href = "xuYiOperatorManage.html";
                                        });
                                    }
                                });
                            },
                            complete: function () {

                            },
                            error: function (data) {
                                layer.msg('系统异常，请联系管理员处理!');
                            }
                        });
                    });

                } else if (obj.event === 'edit') {
                    layer.open({
                        type:2,//弹出iframe层
                        title:'修改运维人员信息',
                        area: ['380px', '330px'],
                        content:'xuYiOperatorModify.html?operatorId=' + data.operatorId,
                    });
                }
            });

            $('#find').on('click', function () {
                // console.log(document.getElementById("operatorName").value)
                table.reload('modelReload', {
                    method: 'post',
                    page: {
                        curr: 1
                    },
                    where: {
                        operatorName:$("#operatorName").val(),
                        talkingCoding:$("#talkingCoding").val()
                    }
                });

            });
        });

    </script>
    <script type="text/html" id="barDemo">
        <a href="#" lay-event="edit">编辑</a>&nbsp;&nbsp;&nbsp;
        <a href="#" lay-event="del">删除</a>
    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
              <span class="layui-breadcrumb" lay-separator="|">
                <a href="javascript:returnIndex2()">首页&nbsp;</a>
                <a href=""> &nbsp;系统管理&nbsp; </a>
                <a href=""> &nbsp;运维人员配置</a>
              </span>
        </div>
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item" style="margin-bottom: 0px">

                        <label class="layui-form-label" style="width: 120px">运维人员名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="operatorName" id="operatorName" autocomplete="off" class="layui-input"
                                   placeholder="" lay-verify="required" style="width:180px">
                        </div>

                        <label class="layui-form-label" style="width: 120px">和对讲编码</label>
                        <div class="layui-input-inline">
                            <input type="text" name="talkingCoding" id="talkingCoding" autocomplete="off" class="layui-input"
                                   placeholder="" lay-verify="required" style="width:180px">
                        </div>

                        <div class="layui-inline" pane="">
                            <button class="layui-btn layui-btn-normal" id="find">查询</button>
                            <button class="layui-btn layui-btn-normal" type="button" onclick="addOperator()">添加</button>
                        </div>



                        <div class="layui-form-item" style="display: flex; padding-top: 18px;padding-bottom: 0px">
                            <button type="button" class="layui-btn" id="import" >
                                <i class="layui-icon"></i>运维人员信息导入
                            </button>
                            <span><a href="/xuYiOperator/download" style="padding-right: 40px;">（模板下载）</a></span>

                            <button class="layui-btn layui-btn-normal" id="upload">上传</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="table-box">
                <table class="layui-table" id="table" lay-filter="demo">
                </table>
            </div>
        </div>
    </div>
</div>
</body>
</html>